﻿using Century.Business.CMS;
using Century.Model.CMS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Century.Web.UI.MVC
{
    public class FrameworkToken
    {
        public static UserToken UserToken
        {
            get
            {
                if (HttpContext.Current.Session["CenturyUserToken"] == null)
                {
                    //TODO: Fill (return to login page)

                    ISiteService siteService = new SiteService();
                    Site defaultSite = siteService.GetDefaulSite();
                    if (defaultSite == null)
                    {
                        defaultSite = new Site { Culture = "en-US",IsDefault = true, IsActive=true, Name = "Global", ContryCode = "en", LanguageCode = "en", LocalName = "Global", Flag = "en.png" };
                        siteService.AddNewSite(defaultSite);
                    }

                    HttpContext.Current.Session["CenturyUserToken"] = new UserToken
                    {
                        CurrentSite = defaultSite,
                        //AccessibleSites = new List<Site> { defaultSite }

                    };
                }
                return (UserToken)HttpContext.Current.Session["CenturyUserToken"];
            }
            set
            {
                HttpContext.Current.Session["CenturyUserToken"] = value;
            }
        }


    }

    public class UserToken
    {
        /// <summary>
        /// Can be culture list, site id list or very thing else which user has access
        /// </summary>
        //public List<Site> AccessibleSites { get; set; }
        public Site CurrentSite { get; set; }
    }
}
